import { request } from "../../utlis/asyncWx"
Page({
  data: {
    swiperList: [],
    cateList: [],
    floorList: [],
    interval: 1000
  },
  onLoad: function (options) {
    // 请求轮播图 分类 底部数据
    this.getSwiperList();
    this.getCateList();
    this.getFloorList();
  },
  // 轮播图
  getSwiperList() {
    request({
      url: 'home/swiperdata',
      header: {
        'content-type': 'application/json'
      },
    }).then(res => {
      // console.log(res)goods_detail/main
      let swiperList = res.data.message
      swiperList.forEach(v => {
        v.navigator_url = v.navigator_url.replace(/main/, "goods_detail")
        // console.log(v.navigator_url);
      })
      this.setData({ swiperList })
    })
  },
  // 分类
  getCateList() {
    request({
      url: 'home/catitems',
      header: {
        'content-type': 'application/json'
      },
    }).then(res => {
      // console.log(res)
      this.setData({
        cateList: res.data.message
      })
    })
  },
  // 底部
  getFloorList() {
    request({
      url: 'home/floordata',
      header: {
        'content-type': 'application/json'
      },
    }).then(res => {
      // console.log(res)
      let floorList = res.data.message
      floorList.forEach(v => {
        v.product_list.forEach(v => {
          v.navigator_url = v.navigator_url.replace(/goods_list/, `goods_list/goods_list`)
          // console.log(v.navigator_url);
        })
      })
      this.setData({ floorList })
    })
  }
});